﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WcfContrib.Showcase.Client
{
    //Be sure to check all the behavior extensions you can implement

    class MaxRcvdMsgSizeBoostExtensionAttribute : Attribute, WcfContrib.Client.Behaviors.IClientChannelHandlerBehavior, WcfContrib.Client.Behaviors.IClientEndpointBehavior
    {
        #region IClientChannelHandlerBehavior Members

        public void ChannelFactoryCreated(WcfContrib.Client.ClientChannel clientChannel, System.ServiceModel.ChannelFactory factory)
        {
            Helpers.WriteLine(ConsoleColor.Blue, "MaxRcvdMsgSizeExtensionAttribute.ChannelFactoryCreated()");

            ((BasicHttpBinding)factory.Endpoint.Binding).MaxReceivedMessageSize = int.MaxValue;
            ((BasicHttpBinding)factory.Endpoint.Binding).MaxBufferSize = int.MaxValue;
            ((BasicHttpBinding)factory.Endpoint.Binding).MaxBufferPoolSize = int.MaxValue;
        }

        public void ChannelCreated(WcfContrib.Client.ClientChannel clientChannel, System.ServiceModel.ICommunicationObject channel)
        {
        }

        #endregion

        #region IClientEndpointBehavior Members

        public void ApplyClientBehavior(WcfContrib.Client.ClientChannel clientChannel, WcfContrib.Client.Description.ClientEndpointDescription endpointDescription)
        {
            endpointDescription.ChannelHandlers.AddUnique(this);
        }

        #endregion
    }
}
